<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8 without BOM">
        <title></title>
        <link rel="stylesheet" href="../../Public/css/960.css" type="text/css" media="screen" charset="utf-8" />
        <link rel="stylesheet" href="../../Public/css/template.css" type="text/css" media="screen" charset="utf-8" />
        <link rel="stylesheet" href="../../Public/css/colour.css" type="text/css" media="screen" charset="utf-8" />

        <script src="../../Public/js/mootools-core.js" type="text/javascript"></script>
        <script src="../../Public/js/mootools-more.js" type="text/javascript"></script>
        <script src="../../Public/js/Source/Locale.en-US.DatePicker.js" type="text/javascript"></script>
        <script src="../../Public/js/Source/Picker.js" type="text/javascript"></script>
        <script src="../../Public/js/Source/Picker.Attach.js" type="text/javascript"></script>
        <script src="../../Public/js/Source/Picker.Date.js" type="text/javascript"></script>
        <link href="../../Public/js/Source/datepicker.css" rel="stylesheet"/>


        <script type="text/javascript">
            function GetId(id)
            {
                return document.getElementById(id);
            }

            function ChkAddress(a)
            {
                x=GetId('msgCity');
                if(a.trim().length==0)
                {
                    x.style.display='block';
                }
                else x.style.display='none';
            }


            function ChkForm(form)
            {
                var count=0;
                with(form){
                    x=GetId('msgCity');
                    if(dtname.value.trim().length==0)
                    {
                        x.style.display='block';
                        count++;
                        //return false;
                    }
                    else x.style.display='none';


                }
                if(count==0 && confirm("Are you sure?"))
                {
                    return true;
                }
                else
                    return false;
            }

            window.addEvent('domready', function(){

                new Picker.Date($$('.birthDate'), {
                    toggle: $$('.myLink')
                });
            });
        </script>
    </head>
    <body>

        <?php
        include_once '../../Include/dbconnect.php';
        include_once '../../Model/user.php';
        include_once '../header.php';
        include_once '../menu.php';
        ?>

        <div id="content" class="container_16 clearfix">
            <div class="grid_16">
                <h2>
                    <span >View and search</span>
                </h2>
            </div>
            <!-- Search -->
            <form id="search"   method="get" action="#">
               
                <div class="grid_2">
                    <span>Họ Và tên:</span>
                    <input type="text" name="name" id="tacgia" style="width: 100px"
                           value="<?php if(isset ($_GET['name'])) echo $_GET['name']; ?>">
                    

                </div>
                <div class="grid_2">
                    <span>Ngày Sinh:</span>
                    <input type="text" name="birthday" id="dFin1" readonly="readonly" class="birthDate"
                           value="<?php if(isset ($_GET['birthday'])) echo $_GET['birthday']; ?>">
                    
                    <span id="msgC1" ><a class="myLink">Calendar</a></span>
                </div>
                <div class="grid_2">
                    <span>Nghề Nghiệp</span>
                     <input type="text" name="job" id="tacgia" style="width: 100px"
                           value="<?php if(isset ($_GET['job'])) echo $_GET['job']; ?>">

                </div>

                <div class="grid_2">
                    <br/>
                    <input type="submit" value="search" >
                </div>
            </form>
            <!-- end  Search -->
             <div style="clear: both; margin: 10 0 0 10px;">
                <?php
                if(isset ($_GET['s'])&&$_GET['s']==1)
                    echo "<p>Đã cập nhật thành công !</p>"
                ?>

            </div>
            <div id="ctl00_ContentPlaceHolder1_plView">

                <div class="grid_16" align="left">

                    <br/>
                    <a  href="edit.php" style="color:highlight;font-size:Large;font-weight:bold;">Add New</a>
                </div>
                <div class="grid_10">


                    <div>

                        <table class="gridview" cellspacing="0" cellpadding="5" rules="all" border="1" style="border-collapse:collapse;">
                            <tr>
                                <th scope="col">Id</th>
                                <th scope="col">Họ tên</th>
                                <th scope="col">Ngày Sinh</th>
                                <th scope="col">Giới tính</th>
                                <th scope="col">Nghề nghiệp</th>
                                <th scope="col">Thao tác</th>

                            </tr>
                            <?php
                            $user = new user();
                            $numPage = $user->countAll(15, $mysqli,$_GET['name'],$_GET['birthday'],$_GET['job']);

                            $link = "";
                            for ($i = 1; $i <= $numPage; $i++) {
                                $link.= "<a href='select.php?name=".$_GET['name']."&birthday=".$_GET['birthday']."&job=".$_GET['job']."&page=" . $i . "'>" . $i . "</a>|";
                            }
                            $link = substr($link, 0, strlen($link) - 2);
                            $pIndex = $_REQUEST["page"];
                            if ($pIndex < 1 | $pIndex > $numPage) {
                                $pIndex = 1;
                            }
                           // $dob = date("Y-m-d",  strtotime($_POST['birthday']));

                            if (!isset($_GET['name']))
                                $_GET['name'] = 0;
                            if (!isset($_GET['birthday']))
                                $_GET['birthday'] = 0;
                            if (!isset($_GET['job']))
                                $_GET['job'] = 0;
                            $result = $user->getAll($pIndex, 15, $mysqli,$_GET['name'],$_GET['birthday'],$_GET['job']);
                            for ($i = 0; $i < count($result); $i++) {
                            ?>
                                <tr>
                                    <td><?php echo $result[$i]->getId(); ?></td>
                                    <td><?php echo $result[$i]->getName(); ?></td>
                                    <td><?php echo $result[$i]->getBirthDay(); ?></td>
                                    <td><?php
                                if ($result[$i]->getSex() == 0)
                                    echo "Nữ";
                                else
                                    echo "Nam";
                            ?></td>
                                <td><?php echo $result[$i]->getJob(); ?></td>
                                <td>
<?php ?>
                                    <a href="../../Controller/access.php?del=<?php echo $result[$i]->getId(); ?>">Xóa</a>
                                    <a href="edit.php?id=<?php
                                    echo $result[$i]->getId() . '&name=' . $result[$i]->getName() .
                                    '&birthday=' . $result[$i]->getBirthDay() . '&sex=' . $result[$i]->getSex() . '&job=' . $result[$i]->getJob();
?>">Sửa</a>
                            <?php ?></td>
                                    </tr>
                            <?php
                                }
                            ?>
                                <tr>
                                    <td colspan="6">Trang(<?php echo $pIndex . "/" . $numPage . "):" . $link ?></td>
                                </tr>
                            </table>

                        </div>

                    </div>

                </div>

            </div>
        <?php
                                include_once '../footer.php';
        ?>

    </body>
</html>
